package com.qms.tubu.adapter;

import android.content.Context;
import android.support.v4.app.Fragment;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.signature.StringSignature;
import com.qms.tubu.R;
import com.qms.tubu.bean.RecommendBean;

/**
 * Created by Mad on 2015/7/16.
 */
public class RecommendAdapter extends LoadMoreAdapter<RecommendBean>{
    private Fragment mFragment;
    public RecommendAdapter(Context context,Fragment fragment) {
        super(context);
        mFragment=fragment;
    }

    @Override
    public int getItemViewType(int position) {
        if(position==mList.size())
            return super.getItemViewType(position);
        else
        {
            RecommendBean recommend=mList.get(position);
            if(recommend.getType().equals("Scenic"))
                return 2;
            else
                return 1;
        }
    }



    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        if(viewType==1)
        {
            View view=LayoutInflater.from(mContent).inflate(R.layout.recommend_module_item,parent,false);
            return new ModuleHolder(view);
        }
        else if(viewType==2)
        {
            View view=LayoutInflater.from(mContent).inflate(R.layout.rencommend_scenic_item,parent,false);
            return new ScenicHolder(view);
        }
        else
            return  super.onCreateViewHolder(parent,viewType);
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {
        if(getItemViewType(position)==1)
        {
            RecommendBean recommend=mList.get(position);
            ModuleHolder moduleHolder= (ModuleHolder) holder;
            Glide.with(mFragment).load(recommend.getImage())
                    .centerCrop()
                    .crossFade()
                    .into(moduleHolder.image);
            moduleHolder.name.setText(recommend.getName());
            moduleHolder.content.setText(recommend.getContent());
        }
        if(getItemViewType(position)==2)
        {
            RecommendBean recommend=mList.get(position);
            ScenicHolder scenicHolder= (ScenicHolder) holder;
            Glide.with(mFragment).load(recommend.getImage())
                    .centerCrop()
                    .crossFade()
                    .into(scenicHolder.image);
            scenicHolder.name.setText(recommend.getName());
            scenicHolder.content.setText(recommend.getContent());
        }
    }
    private class ModuleHolder extends ClickViewHolder {
        private ImageView image;
        private TextView name;
        private TextView content;
        public ModuleHolder(View itemView) {
            super(itemView);
            image= (ImageView) itemView.findViewById(R.id.recommend_module_image);
            name= (TextView) itemView.findViewById(R.id.recommend_module_name);
            content= (TextView) itemView.findViewById(R.id.recommend_module_content);
        }

    }
    private class ScenicHolder extends ClickViewHolder{
        private ImageView image;
        private TextView name;
        private TextView content;
        public ScenicHolder(View itemView) {
            super(itemView);
            image= (ImageView) itemView.findViewById(R.id.recommend_scenic_image);
            name= (TextView) itemView.findViewById(R.id.recommend_scenic_name);
            content= (TextView) itemView.findViewById(R.id.recommend_scenic_content);
        }
    }
}
